Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PC-31475)[ADAGE] feat: Add an attribut in brevo for Marseille en Grand #13941

Conversation

rprasquier-pass
Copy link
Contributor

But de la pull request

Ticket Jira (ou description si BSR) : https://passculture.atlassian.net/browse/PC-31475

Vérifications

  • J'ai écrit les tests nécessaires
  • J'ai mis à jour le fichier des plans de tests du portail pro si nécessaire
  • J'ai mis à jour la liste des routes et des titres de pages du portail pro si j'en ai rajouté/modifié ou supprimé une.
  • J'ai relu attentivement les migrations, en particulier pour éviter les locks, et je préviens les équipes Shérif et Data
  • J'ai ajouté des screenshots pour d'éventuels changements graphiques

@rprasquier-pass rprasquier-pass force-pushed the PC-31475-eac-back-avoir-un-attribut-sur-brevo-permettant-de-reperer-les-ac-participant-a-meg branch from 410c7f3 to 0c9765d Compare September 3, 2024 08:38
@rprasquier-pass rprasquier-pass marked this pull request as ready for review September 3, 2024 13:04
@rprasquier-pass rprasquier-pass marked this pull request as draft September 3, 2024 13:05
@rprasquier-pass rprasquier-pass force-pushed the PC-31475-eac-back-avoir-un-attribut-sur-brevo-permettant-de-reperer-les-ac-participant-a-meg branch 10 times, most recently from f792131 to 13393a9 Compare September 4, 2024 14:29
Comment on lines 286 to 289
joinedload(offerers_models.Venue.collectiveOffers)
.subqueryload(educational_models.CollectiveOffer.institution)
.subqueryload(educational_models.EducationalInstitution.programs)
.load_only(educational_models.EducationalInstitutionProgram.name),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai très peur de cette jointure qui, associée à d'autres, va faire exploser le nombre de lignes.
Mieux vaut faire une requête séparée sur les offres collectives.
Tu peux aussi ajouter des load_only sur CollectiveOffer et EducationalInstitution pour ne rapatrier de la base de données que les colonnes utiles.

Mais je pense même que plutôt que rapatrier toutes les offres, tu pourrais faire la déduction de has_collective_offers_marseille_en_grand directement côté postgresql, qui serait quelque chose comme :

select exists(
    select 1
    from collective_offer
    join educational_institution on educational_institution.id = collective_offer."institutionId"
    join educational_institution_program_association on educational_institution_program_association."institutionId" = educational_institution.id
    join educational_institution_program on educational_institution_program.id = educational_institution_program_association."programId"
    where collective_offer."venueId" = ...
    and educational_institution_program.name = 'marseille_en_grand'
    limit 1
);

ce qui a le mérite de ne demander à la base de données que true ou false plutôt que demander toutes les données uniquement dans ce but, et faire le calcul en Python.

Je me pose également une question en plus : ne veut-on pas avoir eac_meg à True uniquement si des réservations ont été faites par les établissements pendant une période du programme ? En ignorant des réservations antérieures ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai intégré cela dans une methode dédié (cf dernier commit).

Pour ta question sur la période du programme : cela n'a pas été demandé.

@@ -91,6 +91,7 @@ class ProAttributes:
has_banner_url: bool | None = (
None # Set to False when at least one permanent venue doesn't have a banner URL, True otherwise
)
eac_meg: bool | None = None # At least one collective offer with 'Marseille en Grand'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Un is ou has dans le nom de l'attribut serait plus cohérent avec le nommage des autres booléens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Comment on lines 225 to 243
num_queries = EXPECTED_PRO_ATTR_NUM_QUERIES
if create_permanent:
num_queries += 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La requête en plus vient semble-t-il des subqueryload de ta requête (j'ai testé sur ta branche, plus besoin de ce changement en remplaçant les subqueryload par des joinedload).
Mais comme je parle de revoir la requête plus haut, ça changera probablement ce qu'ont teste ici.

num_queries = EXPECTED_PRO_ATTR_NUM_QUERIES
if create_permanent:
num_queries += 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne vois aucun test qui vérifie la valeur collectée de l'attribut eac_meg, il serait utile de vérifier que la logique est bonne, qu'elle soit exécutée en Python ou par postgreSQL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est vrai, je vais intégrer cela

@rprasquier-pass rprasquier-pass force-pushed the PC-31475-eac-back-avoir-un-attribut-sur-brevo-permettant-de-reperer-les-ac-participant-a-meg branch 2 times, most recently from ad5349a to 6f05f26 Compare September 4, 2024 18:38
)
.join(educational_models.EducationalInstitutionProgram, educational_models.EducationalInstitution.programs)
.filter(
sa.and_(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Détail : le and_ n'est pas nécessaire car les arguments de filter sont associés en AND.

api/src/pcapi/core/educational/repository.py Show resolved Hide resolved
@@ -287,12 +288,22 @@ def get_pro_attributes(email: str) -> models.ProAttributes:
.all()
)

if has_collective_offers:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attention ici, tu utilises has_collective_offers qui est calculé en recherchant par adresse email de compte pro, comme condition alors que tu calcules has_collective_offers_marseille_en_grand à partir des lieux collectés en recherchant par venue.bookingEmail. Je crains qu'on puisse se retrouver avec des incohérences, car has_collective_offers sera False si l'email est utilisé uniquement dans venue.

En intuition rapide, je me dis que la condition pour faire la requête pourrait être sur quelque chose comme any(venue.adageId for venue in venues).

Je te laisse vérifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En fait le critère any(venue.adageId for venue in venues) n'est pas suffisant => il peut y avoir un lieux qui réaliser des projets collectif (pour marseille en grand) en dehors de l'établissement scolaire. Il faut donc a minima faire une première requete pour savoir si les lieux en questions ont été utilisé pour des offres collectives.

Puisqu'on doit faire une requête dans tous les cas. Je propose de supprimé la condition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne comprends pas bien : si le lieu n'a pas d'adageId, alors il ne peut pas proposer d'offre collective, donc n'aura jamais une offre reliée à un établissement scolaire relié lui-même au programme MEG. Mais il me manque peut-être des infos métier, qu'ai-je loupé ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tu as raison -> il y a forcément un lieu de rattachement. Ne pas tenir compte de ma remarque précédente.

@@ -89,6 +89,7 @@ class SendinblueAttributes(Enum):
VENUE_NAME = "VENUE_NAME"
VENUE_TYPE = "VENUE_TYPE"
IS_EAC = "IS_EAC"
IS_EAC_MEG = "IS_EAC_MEG"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attention par contre sur le nommage de l'attribut Brevo, car le marketing a déjà créé un attribut EAC_MEG, donc il faudra "tomber en face".
Référence : https://my.brevo.com/lists/add-attributes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

je pensais en profiter pour créé un nouvel attribut (ce qui permettrait de ne pas effacer le travail de Lin).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok pas de souci, il faut juste prévenir le marketing pro.


class HasCollectiveOffersForProgramAndVenueIdsTest:

def test_has_collective_offers_for_program_and_venueids_test(self, app):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ce test est pertinent mais n'est pas suffisant pour vérifier que la fonction ici testée est appelée quand il faut. Cf. mon commentaire plus haut. Je pensais à un test dans external_pro_test.py, par exemple avec deux lieux dont le bookingEmail correpond à l'email, dont un avec une offre MEG, mais aucun compte pro n'ayant cet email.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu as raison, mon push d'hier soir avec ce test n'est pas passé...

@rprasquier-pass rprasquier-pass force-pushed the PC-31475-eac-back-avoir-un-attribut-sur-brevo-permettant-de-reperer-les-ac-participant-a-meg branch 12 times, most recently from e08b94b to 2d71538 Compare September 6, 2024 16:25
@rprasquier-pass rprasquier-pass marked this pull request as ready for review September 9, 2024 07:33
venue_with_collective_offer = any(venue.adageId for venue in venues)

if venue_with_collective_offer:
venue_ids = {venue.id for venue in venues}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Queston : Pourquoi ne pas garder uniquement les ID des lieux avec adageId ?
Quoique...tout d’un coup j’ai un doute : un vague souvenir qu’un lieu peut créer une offre collective si n’importe quel lieu de la même structure a un adageId. Ça remettrait en cause ce que je disais avant, mais je n’y pense que maintenant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Du coup tu préconises de faire l'appel en base has_collective_offers_for_program_and_venue_ids("marseille_en_grand", venue_ids) dans tous les cas de figure ? Est-ce que cela ne va pas avoir un coup trop important pour un scénario très marginal (il me semble) ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne suis pas certain du scénario, ni qu'il soit si marginal.
Mais on doit pouvoir faire une recherche dans la base de données pour voir l'ampleur des offres collectives créées sur des lieux sans adageId.
Je ne maîtrise pas suffisamment toutes les règles métier EAC.

@rprasquier-pass rprasquier-pass force-pushed the PC-31475-eac-back-avoir-un-attribut-sur-brevo-permettant-de-reperer-les-ac-participant-a-meg branch 3 times, most recently from f0fb275 to 145cb92 Compare September 11, 2024 10:14
We must test all relevant venue (not only those with adageId)
@rprasquier-pass rprasquier-pass force-pushed the PC-31475-eac-back-avoir-un-attribut-sur-brevo-permettant-de-reperer-les-ac-participant-a-meg branch from 145cb92 to ad4384e Compare September 11, 2024 13:58
@rprasquier-pass rprasquier-pass merged commit 8cdced8 into master Sep 11, 2024
23 checks passed
@rprasquier-pass rprasquier-pass deleted the PC-31475-eac-back-avoir-un-attribut-sur-brevo-permettant-de-reperer-les-ac-participant-a-meg branch September 11, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants